package com.unknowpupil.service;

import com.unknowpupil.utils.DateUtils;
import com.unknowpupil.utils.SendEmailUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created at 2020/11/4 by w10g <br>
 * Initialize HealthService ... <br>
 *
 * @author unknowpupil
 * @since 0.0.1
 */
@Slf4j
@Component
public class HealthService {
    @Autowired
    SendEmailUtils sendEmailUtils;


    public void nginxMessage(String exceptionDetail) {
        Date date = new Date();
        Map<String, Object> model = new HashMap<>();
        model.put("serverName", "nginx");
        model.put("exceptionDetail", exceptionDetail);
        model.put("deadTime", DateUtils.dateToStr(date));
        model.put("error", "无法访问");

        try {
            sendEmailUtils.sendMail(model, "nginx任务错误","index.ftl", "772054819@qq.com");
            log.info("邮件发送成功");
        } catch (Exception e) {
            log.error("【邮件发送超时...】", e);
        }
    }
}
